<template>
  <CardVue height="2.5rem" title="综合评价">
    <div class="layout">
      <div class="layout-header">
        <div class="layout-header-item">
          <div class="layout-header-item-title">0-60分</div>
          <div class="layout-header-item-num">{{ info['0-60'] || 0 }}</div>
        </div>
        <div class="layout-header-item">
          <div class="layout-header-item-title">60-80分</div>
          <div class="layout-header-item-num">{{ info['60-80'] || 0 }}</div>
        </div>
        <div class="layout-header-item">
          <div class="layout-header-item-title">80-100分</div>
          <div class="layout-header-item-num">{{ info['80-100'] || 0 }}</div>
        </div>
        <div class="layout-header-item">
          <div class="layout-header-item-title">100分以上</div>
          <div class="layout-header-item-num">{{ info['100以上'] || 0 }}</div>
        </div>
      </div>
      <div class="table">
        <div class="row th">
          <div class="col">排名</div>
          <div class="col">主管部门</div>
          <div class="col">达标率</div>
        </div>
        <div class="body comprehensiveEvaluation">
          <div class="body-scroll">
            <div class="row" v-for="(it, index) in rankingHttpData">
              <div class="col">top{{ index + 1 }}</div>
              <div class="col">
                {{ it.supervisoryUnit || '' }}
              </div>
              <div class="col">
                {{ it?.standardRate ? it?.standardRate.toFixed(0) : 0 }}%
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </CardVue>
</template>
<script setup lang="ts">
import CardVue from '@/views/largeScreen/components/card/card.vue'
import { nextTick, onMounted, ref } from 'vue'
import { portrait, rankingHttp } from '@/api/spotCheck/spotCheck'
const info = ref({
  '0-60': 0,
  '60-80': 0,
  '80-100': 0,
  '100以上': 0
})

interface RankingHttp {
  standardRate: number
  supervisoryUnit: string
}
const rankingHttpData = ref<RankingHttp[]>([])

onMounted(() => {
  portrait().then((res) => {
    info.value = res
  })
  rankingHttp().then((res) => {
    rankingHttpData.value = res.data.map((i) => {
      return {
        standardRate: i?.standardRate ? Number(i?.standardRate) * 100 : 0,
        supervisoryUnit: i.supervisoryUnit
      }
    })
    nextTick(() => {
      runScrolling()
    })
  })
})

const scrollAnimeState = ref()

const runScrolling = () => {
  const ul = document.querySelector<HTMLDivElement>(
    '.comprehensiveEvaluation .body-scroll'
  )

  const ls = document.querySelectorAll<HTMLDivElement>(
    '.comprehensiveEvaluation .row'
  )?.length

  let i = 0

  ul!.style.transition = 'all 1s ease'

  scrollAnimeState.value = setInterval(() => {
    if (!ul) return
    i++
    if (i >= ls) {
      i = 1
      ul.style.marginTop = '0'
    }
    ul.style.marginTop = `${-'.39' * i + 'rem'}`
  }, 2400)
}
</script>

<style scoped lang="scss">
.layout {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding-top: 0.1rem;
  .layout-header {
    width: 100%;
    height: 0.5rem;
    display: flex;
    .layout-header-item {
      flex: 1;
      min-width: 0;
      //width: 1rem;
      .layout-header-item-title {
        font-size: 0.2rem;
        color: #0478cd;
        text-align: center;
        padding-bottom: 0.05rem;
        border-bottom: 1px solid #922ade;
        position: relative;
      }
      .layout-header-item-title::before {
        content: '';
        width: 1px;
        height: 0.1rem;
        position: absolute;
        left: 0;
        bottom: 0;
        background-color: #922ade;
      }
      .layout-header-item-num {
        font-size: 0.15rem;
        color: #fff;
        text-align: center;
        margin-top: 0.05rem;
      }
    }
  }
  .table {
    width: 100%;
    height: calc(100% - 0.5rem);
    box-sizing: border-box;
    padding: 0.1rem 0;

    .body {
      overflow-y: scroll;
      height: calc(100% - 0.3rem);
    }
    .row {
      width: 100%;
      display: flex;
      margin-bottom: 0.09rem;
      height: 0.3rem;
      .col {
        color: #04f5d3;
        font-size: 0.2rem;
      }
      .col:nth-child(1) {
        width: 0.8rem;
        text-align: center;
      }
      .col:nth-child(2) {
        flex: 1;
        min-width: 0;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .col:nth-child(3) {
        width: 1rem;
        text-align: center;
      }
    }
    .body::-webkit-scrollbar {
      display: none; /* 隐藏滚动条 */
    }
    .row:last-child {
      margin-bottom: 0;
    }
    .th {
      .col {
        color: #04f5d3;
        font-size: 0.22rem;
        font-weight: 700;
      }
    }
  }
}
</style>
